core: Support a per-remote "proxy" configuration option
authorColin Walters <walters@verbum.org>
Fri, 25 Jul 2014 11:55:55 +0000 (07:55 -0400)
committerColin Walters <walters@verbum.org>
Mon, 28 Jul 2014 17:49:38 +0000 (13:49 -0400)
We don't want to have to force people to set it in the environment.

https://bugzilla.gnome.org/show_bug.cgi?id=733734

doc/ostree.repo-config.xml
src/libostree/ostree-fetcher.c
src/libostree/ostree-fetcher.h
src/libostree/ostree-repo-pull.c

index bbacdd08ca7f9ff804725536f66a91aaa29c43ca..26fef077024a952d314c55681deb2cc02e458d1d 100644 (file)
@@ -126,6 +126,12 @@ Boston, MA 02111-1307, USA.
         <literal>https</literal>.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><varname>proxy</varname></term>
+        <listitem><para>A string value, if given should be a URL for a
+        HTTP proxy to use for access to this repository.</para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><varname>gpg-verify</varname></term>
         <listitem><para>A boolean value, defaults to true.
index 0ea4d29d8b26fa07343a532be8a4db1e71e05d46..298ba63f6f162409a604ac6bc8ede82ef6e69334 100644 (file)
@@ -172,16 +172,7 @@ _ostree_fetcher_init (OstreeFetcher *self)
   http_proxy = g_getenv ("http_proxy");
   if (http_proxy)
     {
-      SoupURI *proxy_uri = soup_uri_new (http_proxy);
-      if (!proxy_uri)
-        {
-          g_warning ("Invalid proxy URI '%s'", http_proxy);
-        }
-      else
-        {
-          g_object_set (self->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
-          soup_uri_free (proxy_uri);
-        }
+      _ostree_fetcher_set_proxy (self, http_proxy);
     }
 
   if (g_getenv ("OSTREE_DEBUG_HTTP"))
@@ -224,6 +215,22 @@ _ostree_fetcher_new (GFile                    *tmpdir,
   return self;
 }
 
+void
+_ostree_fetcher_set_proxy (OstreeFetcher *self,
+                           const char    *http_proxy)
+{
+  SoupURI *proxy_uri = soup_uri_new (http_proxy);
+  if (!proxy_uri)
+    {
+      g_warning ("Invalid proxy URI '%s'", http_proxy);
+    }
+  else
+    {
+      g_object_set (self->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
+      soup_uri_free (proxy_uri);
+    }
+}
+
 void
 _ostree_fetcher_set_client_cert (OstreeFetcher *fetcher,
                                 GTlsCertificate *cert)
index 850d3178f8f23c0e30c55ba4fc2998bdc41481ee..0ab1def403b13d731fe8e67834ac5e4bdd0eedcd 100644 (file)
@@ -54,6 +54,9 @@ GType   _ostree_fetcher_get_type (void) G_GNUC_CONST;
 OstreeFetcher *_ostree_fetcher_new (GFile                     *tmpdir,
                                    OstreeFetcherConfigFlags   flags);
 
+void _ostree_fetcher_set_proxy (OstreeFetcher *fetcher,
+                                const char    *proxy);
+
 void _ostree_fetcher_set_client_cert (OstreeFetcher *fetcher,
                                      GTlsCertificate *cert);
 
index 51eb4d0c1be62815781d1903c487ba917ff9559f..76798d6e5983d7411ebe64d80160e3657c8fe004 100644 (file)
@@ -1151,6 +1151,17 @@ ostree_repo_pull (OstreeRepo               *self,
       }
   }
 
+  {
+    gs_free char *http_proxy = NULL;
+
+    if (!ot_keyfile_get_value_with_default (config, remote_key, "proxy",
+                                            NULL, &http_proxy, error))
+      goto out;
+
+    if (http_proxy)
+      _ostree_fetcher_set_proxy (pull_data->fetcher, http_proxy);
+  }
+
   if (!pull_data->base_uri)
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,